package com.sihan.swvp.service.worksy;

import java.util.List;
import java.util.Map;
import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.sihan.swvp.dao.worksy.WorksyDao;
import com.sihan.swvp.entity.worksy.Worksy;
import com.sihan.swvp.entity.worksy.vo.VWorksy;

@Service
public class WorksyService {

	@Autowired
	private WorksyDao worksyDao;
	
	public Page<Map<String, Object>> getList(Integer page,Integer limit,Map<String, Object> kv){
		PageHelper.startPage(page, limit);
		Page<Map<String, Object>> list = worksyDao.getList(kv);
		return list;
	}
	
	public void addWorksy(Worksy worksy){
		if(worksy.getId() != null && !"".equals(worksy.getId())){
			worksyDao.updateWorksy(worksy);
		}else{
			worksy.setId(UUID.randomUUID().toString());
			worksyDao.addWorksy(worksy);
		}
	}
	
	public void delById(String id){
		worksyDao.delById(id);
	}
	
	public List<Map<String, Object>> getBdz(Integer regionId){
		return worksyDao.getBdz(regionId);
	}
	
	public List<Map<String, Object>> getBz(Integer zyId,Integer bzId){
		return worksyDao.getBz(zyId,bzId);
	}
	
	public List<Map<String, Object>> getZy(){
		return worksyDao.getZy();
	}
	
	public List<Map<String, Object>> getDept(){
		return worksyDao.getDept();
	}
	
	public List<Map<String, Object>> getDeptPeople(int dept){
		return worksyDao.getDeptPeople(dept);
	}
	
	public List<Map<String, Object>> getCity(){
		
		return worksyDao.getCity();
	}
	
	public List<Map<String, Object>> inspectSameTask(VWorksy vWorksy){
		return worksyDao.inspectSameTask(vWorksy);
	}
	
	/*public void addimpExcel(List<Worksy> list){
		long st = System.currentTimeMillis();
		long et = 0;
		for (Worksy w : list) {
			//判断系统中是否已有相同编号的数据
			if(worksyDao.getCountById(w.getId()) > 0){
				throw new RuntimeException("系统中已经存在编号为 '"+w.getId()+"' 的数据。在Excel第"+w.getExcelRow()+"行");
			}
			//获取班组ID
			Integer bzid = worksyDao.getBzIdByBzcode(w.getBzCode());
			if(bzid == null){
				throw new RuntimeException("数据导入文件中的班组编码 '"+w.getBzCode()+"' 在系统中不存在。在Excel第"+w.getExcelRow()+"行");
			}
			w.setBz_id(bzid.toString());
			//获取专业ID
			Integer zyid = worksyDao.getZyIdByzyCode(w.getZyCode());
			if(zyid == null){
				throw new RuntimeException("数据导入文件中的专业编码 '"+w.getZyCode()+"' 在系统中不存在。在Excel第"+w.getExcelRow()+"行");
			}
			w.setMajor_id(zyid.toString());
		}
		worksyDao.addWorksylist(list);
		et = System.currentTimeMillis();
		System.out.println((et - st)/1000);
	}*/

}
